﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using SystemCenterSoa.IRepository.SystemManager;
using SystemCenterSoa.PoModel.SystemManager;
using SystemCenterSoa.Repository.CommonLib;

namespace SystemCenterSoa.Repository.SystemManager
{
    public class ArchitecturalTitleRepository : BaseRepository, IArchitecturalTitleRepository
    {
        public ArchitecturalTitleRepository(SystemCenterDbSoaContext systemCenterDbSoaContext) : base(systemCenterDbSoaContext)
        {
        }
        /// <summary>
        /// 分页条件查询
        /// </summary>
        /// <param name="atleName"></param>
        /// <returns></returns>
        public List<ArchitecturalTitlePo> GetArchitecturalTitleList(string atleName)
        {
            //获取全部数据
            var query = _systemCenterDbSoaContext.ArchitecturalTitlePos.AsQueryable();
            if (!string.IsNullOrWhiteSpace(atleName))
            {
                query = query.Where(t => t.atle_name.Contains(atleName));
            }
            return query.OrderBy(t => t.atle_sort).ToList();

        }
        /// <summary>
        /// 添加
        /// </summary>
        /// <param name="ArchitecturalTitle"></param>
        /// <returns></returns>
        public bool GetArchitecturalTitleAdd(ArchitecturalTitlePo ArchitecturalTitle)
        {
            _systemCenterDbSoaContext.ArchitecturalTitlePos.Add(ArchitecturalTitle);
            return _systemCenterDbSoaContext.SaveChanges() > 0;
        }
        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="ids"></param>
        /// <returns></returns>
        public bool GetArchitecturalTitleDel(string ids)
        {
            var ArrId = ids.Split(',');
            foreach (var item in ArrId)
            {
                int id = Convert.ToInt32(item);
                _systemCenterDbSoaContext.ArchitecturalTitlePos.Remove(_systemCenterDbSoaContext.ArchitecturalTitlePos.Find(id));
            }
            return _systemCenterDbSoaContext.SaveChanges() > 0;
        }
        /// <summary>
        /// 反填
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public ArchitecturalTitlePo GetArchitecturalTitleFan(int id)
        {
            return _systemCenterDbSoaContext.ArchitecturalTitlePos.Find(id);
        }
        /// <summary>
        /// 编辑
        /// </summary>
        /// <param name="ArchitecturalTitle"></param>
        /// <returns></returns>
        public bool GetArchitecturalTitleUpdate(ArchitecturalTitlePo ArchitecturalTitle)
        {
            _systemCenterDbSoaContext.Entry(ArchitecturalTitle).State = Microsoft.EntityFrameworkCore.EntityState.Modified;
            return _systemCenterDbSoaContext.SaveChanges() > 0;
        }
    }
}
